function info(msg){
	console.info(msg);
}
function tips(msg,time){
	$.dialog({
        id: 'Tips',
        title: false,
        cancel: false,
        fixed: true,
        lock: false
    }).content('<div style="padding: 0 1em;">' + msg + '</div>').time(time || 3000);
}
function confirm(msg,a,b){
	$.confirm(msg, function () {
	    a ? a() : true;
	}, function () {
	    b ? b() : true;
	});
}

function post(url,data,SuccessCallback,errCallback){
	$.dialog({
        id: 'Loading',
        title: false,
        cancel: false,
        fixed: true,
        content:'<div class="d-content" id="d-content-Loading" style="padding: 20px 25px;"><img src="/Public/artDialog/skins/loading.gif">页面加载中......</div>',
        lock: true
    });
	$.ajax({
		url:url,
		data:data,
		type:'POST',
		dataType:'json',
		success:function(d){
			$.dialog({id: 'Loading'}).close();
			if (d.status==1){
				SuccessCallback ? SuccessCallback(d.info) :tips(d.info);
			}else{
				errCallback ? errCallback(d.info) :tips(d.info);
			}
		},
		error:function(){
			$.dialog({id: 'Loading'}).close();
			tips('服务器返回数据错误!');
		}
	});
}
function get(url,SuccessCallback,errCallback){
	$.dialog({
        id: 'Loading',
        title: false,
        cancel: false,
        fixed: true,
        content:'<div class="d-content" id="d-content-Loading" style="padding: 20px 25px;"><img src="/Public/artDialog/skins/loading.gif">页面加载中......</div>',
        lock: true
    });
	$.ajax({
		url:url,
		dataType:'json',
		success:function(d){
			$.dialog({id: 'Loading'}).close();
			if (d.status==1){
				SuccessCallback ? SuccessCallback(d.info) :tips(d.info);
			}else{
				errCallback ? errCallback(d.info) :tips(d.info);
			}
		},
		error:function(){
			$.dialog({id: 'Loading'}).close();
			tips('服务器返回数据错误!');
		}
	});
}
function sortBy (field,sort){
	location.href = URL+"/index/_order/"+field+"/_sort/"+sort;
}
function sort(id){
	var keyValue;
	keyValue = getSelectCheckboxValues();
	location.href = URL+"/sort/sortId/"+keyValue;
}
function CheckAll(id){
	$(':checkbox[name="key"]').attr('checked',id.checked);
	//changrowbgcolor(false);
}
function adv(o){
	if($('#DataTables_Table_1_filter').css('display')=='none'){
		$('#DataTables_Table_1_filter').show();
		o.innerHTML='隐藏';
		$('#DataTables_Table_1_filter').prepend($('.advitem'));
		//$(o).parent().attr("class","btn adv2");
	}else{
		$('#DataTables_Table_1_filter').hide();
		$('#dataTables_filter').prepend($('#DataTables_Table_1_filter .advitem'));
		//$('#SearchA').attr('class','adv');
		o.innerHTML='高级';
		//$(o).parent().attr("class","btn adv1");
	}
}
function add(id){
	if (id)
	{
		 window.location  = URL+"/add/id/"+id;
	}else{
		 window.location= URL+"/add/";
	}
}
function edit(id){
	var keyValue;
	if (id){
		keyValue = id;
	}else{
		keyValue = getSelectCheckboxValue();
	}
	if (!keyValue){
		tips('请选择编辑项！');
		return false;
	}
	window.location =  URL+"/edit/id/"+keyValue;
}
function doDelete(){
	$('#checkList tbody td').find(':checkbox').each(function(){
		if($(this).attr('checked')=='checked'){
			$(this).parent().parent().empty();
		}
	})
}
function del(id){
    var keyValue;
    if (id)
    {
        keyValue = id;
        $(':checkbox[value="'+keyValue+'"]').attr('checked',true);
    }else {
        keyValue = getSelectCheckboxValues();
    }
    if (!keyValue)
    {
        tips('请选择删除项！');
        return false;
    }
    confirm('确实要删除选择项吗？',function(){
    	get(URL+"/delete/&id="+keyValue+'&ajax=1',doDelete);
    },function(){$(':checkbox[value="'+keyValue+'"]').attr('checked',false);});
}
function getSelectCheckboxValues(){
	var val=new Array();
	$('#checkList td :checkbox').each(function(){
		if($(this).attr('checked')=='checked'){
			val.push($(this).val());
		}
	})
	return val.join(',');
}
function cache(){
	get(URL+"/cache/");
}
function child(id){
	location.href = URL+"/index/pid/"+id;
}